import { api } from './request'

/**
 * 会员等级管理相关API接口
 */
export const memberLevelApi = {
  /**
   * 获取会员等级列表
   * @param params 查询参数
   */
  getMemberLevelList: (params: {
    page: number
    pageSize: number
    name?: string
    status?: number
  }) => {
    return api.get('/member-level/list', params)
  },

  /**
   * 获取所有会员等级
   */
  getAllMemberLevels: () => {
    return api.get('/member-level/all')
  },

  /**
   * 添加会员等级
   * @param data 会员等级数据
   */
  addMemberLevel: (data: {
    name: string
    code: string
    description?: string
    minPoints: number
    maxPoints: number
    discount: number
    status: number
    sort: number
  }) => {
    return api.post('/member-level/add', data)
  },

  /**
   * 编辑会员等级
   * @param data 会员等级数据
   */
  updateMemberLevel: (data: {
    id: number
    name: string
    code: string
    description?: string
    minPoints: number
    maxPoints: number
    discount: number
    status: number
    sort: number
  }) => {
    return api.put('/member-level/update', data)
  },

  /**
   * 删除会员等级
   * @param id 会员等级ID
   */
  deleteMemberLevel: (id: number) => {
    return api.delete(`/member-level/delete/${id}`)
  },

  /**
   * 获取会员等级权益
   * @param id 会员等级ID
   */
  getMemberLevelBenefits: (id: number) => {
    return api.get(`/member-level/benefits/${id}`)
  },

  /**
   * 设置会员等级权益
   * @param data 会员等级权益数据
   */
  setMemberLevelBenefits: (data: {
    levelId: number
    benefits: Array<{
      name: string
      description?: string
      type: number
      value: string
      sort: number
    }>
  }) => {
    return api.post('/member-level/set-benefits', data)
  }
}